package hlhj.fhp.checkpoint.customView

import android.content.Context
import android.support.v7.widget.GridLayoutManager
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.PopupWindow
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.adp.ChooseYearLocPopAdp
import hlhj.fhp.checkpoint.javaBean.YearLimitBean
import kotlinx.android.synthetic.main.pop_choose_loc.view.*

/**
 * Created by Never Fear   on 2018\11\26 0026.
Never More....
 */
class ChooseYearLocationPop(private val c:Context) :PopupWindow() {
    private var chooseYearLocAdp:ChooseYearLocPopAdp?=null
    private val datas=ArrayList<YearLimitBean.InfoBean>()
    var listener:OnYearLocClick?=null
    init {
        this.width= LinearLayout.LayoutParams.WRAP_CONTENT
        this.height= LinearLayout.LayoutParams.WRAP_CONTENT
        this.isOutsideTouchable=true
        this.isFocusable=true
        init()
    }

    private fun init() {
        contentView= LayoutInflater.from(c).inflate(R.layout.pop_choose_loc,null)
        this.animationStyle= R.style.rulePopStyle

        setList()
    }

    private fun setList() {
        chooseYearLocAdp= ChooseYearLocPopAdp(datas)
        contentView.locRecy.adapter=chooseYearLocAdp
        contentView.locRecy.layoutManager = GridLayoutManager(c, 5)
        chooseYearLocAdp?.setOnItemClickListener { adapter, view, position ->
            listener?.click(datas[position].provinceSimple,datas[position].check_price)
        }

    }

    fun refreshList(refreshData:ArrayList<YearLimitBean.InfoBean>){
        datas.clear()
        datas.addAll(refreshData)
        chooseYearLocAdp?.notifyDataSetChanged()
    }

    interface OnYearLocClick{
        fun click(loc:String,money:String)
    }
}